package com.gopay.bis.ccb.bcdl.impl;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.gopay.bis.ccb.bcdl.operation.CcbBcdlManager;
import com.gopay.common.domain.bank.BcdlMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.businesses.BcdlService;

public class CcbBcdlServiceImpl implements BcdlService {

    private final static Logger logger = LoggerFactory.getLogger("BANK_LOG");


    private Map<String, CcbBcdlManager> realManager;

    @Override
    public Object query(Object object) throws GopayException {
        // TODO Auto-generated method stub
        BcdlMessage msg = (BcdlMessage) object;
        CcbBcdlManager ccbBcdlManager = realManager.get(msg.getLabel());
        if (null == ccbBcdlManager) {
            logger.error("can not find ccbBcdlManager for eft, BankOrderId:" + msg.getBankOrderId());
            throw new RuntimeException("can not find bcdlservice for eft, BankOrderId:" + msg.getBankOrderId());
        }
        return ccbBcdlManager.query(object);
    }

    @Override
    public Object eft(Object object) throws GopayException {
        // TODO Auto-generated method stub
        BcdlMessage msg = (BcdlMessage) object;
        CcbBcdlManager ccbBcdlManager = realManager.get(msg.getLabel());
        if (null == ccbBcdlManager) {
            logger.error("can not find ccbBcdlManager for eft, BankOrderId:" + msg.getBankOrderId());
            throw new RuntimeException("can not find bcdlservice for eft, BankOrderId:" + msg.getBankOrderId());
        }
        return ccbBcdlManager.eft(object);
    }

    @Override
    public Object queryBalance(Object object) throws GopayException {
        // TODO Auto-generated method stub
        BcdlMessage msg = (BcdlMessage) object;
        CcbBcdlManager ccbBcdlManager = realManager.get(msg.getLabel());
        if (null == ccbBcdlManager) {
            logger.error("can not find ccbBcdlManager for eft, BankOrderId:" + msg.getBankOrderId());
            throw new RuntimeException("can not find bcdlservice for eft, BankOrderId:" + msg.getBankOrderId());
        }
        return ccbBcdlManager.queryBalance(object);
    }

    public void setRealManager(Map<String, CcbBcdlManager> realManager) {
        this.realManager = realManager;
    }

    @Override
    public Object packetEft(Object object) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object queryPacket(Object object) throws GopayException {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Object queryAcctDetail(Object object) throws GopayException {
        BcdlMessage msg = (BcdlMessage) object;
        CcbBcdlManager ccbBcdlManager = realManager.get(msg.getLabel());
        if (null == ccbBcdlManager) {
            throw new RuntimeException("can not find queryAcctDetail for eft, BankOrderId:" + msg.getBankOrderId());
        }
        return ccbBcdlManager.queryAcctDetail(object);
    }
	




}
